import React, { Component } from 'react';
import axios from '../../axios/index'
export default class OAuth extends Component {

constructor(props){
    super(props);
}

  componentDidMount(){
    let paramsArr =this.props.location.search.split("=");
    let codeArr =paramsArr[1].split("&");
    let code=codeArr[0];
    console.log('code:',code);
    if(code!=undefined || code!=null){
      axios.ajax({
        url:'/api/v1/user/wechatLogin',
        method:'get',
        data:{
          code:code
        }
      }).then((res)=>{
          if(res){
            console.log('w微信登录成功：',res.data.accessToken);
              //授权登录成功，存储accessToken，跳转到首页
              window.localStorage.accessToken=res.data.accessToken;
              if(window.localStorage.userInfo==undefined || window.localStorage.userInfo==null || window.localStorage.userInfo=='' ){
                this.props.history.push('/login');
              }else{
                this.props.history.push('/main');
              }
          }
      });
    }else{
      
    }
  }
    render() {
        return (
        <div>
        
        </div>
        );
    }
}

